package com.yuanxin.chooseimage.zxing;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.ViewGroup;

import com.yuanxin.chooseimage.R;


public class ScanErCodeView extends ViewGroup {
    private static String TAG = "ScanErCodeView";

    private ViewfinderView viewfinderView;
    private SurfaceView surfaceView;

    public ScanErCodeView(Context context) {//当View view = new View(context);
        this(context, null);
    }

    public ScanErCodeView(Context context, AttributeSet attrs) {//xml中定义，包含自定义属性
        this(context, attrs, -1);
    }

    public ScanErCodeView(Context context, AttributeSet attrs, int defStyle) {//也是xml定义，包含自定义属性和主题
        super(context, attrs, defStyle);
//        viewfinderView = new ViewfinderView(context,attrs);
//        surfaceView = new SurfaceView(context);
////        ViewGroup.MarginLayoutParams marginLayoutParams=new ViewGroup.MarginLayoutParams(100,100);
////        marginLayoutParams.topMargin=-(100);
////        surfaceView.setLayoutParams(marginLayoutParams);
////        setFitsSystemWindows(true);
//        addView(surfaceView);
//        addView(viewfinderView);
        LayoutInflater.from(context).inflate(R.layout.capture_scan, this);
        viewfinderView = findViewById(R.id.viewfinder_view_scan);
        surfaceView = findViewById(R.id.preview_view_scan);
    }

    //    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        int width = resolveSize(getResources().getDisplayMetrics().widthPixels,widthMeasureSpec);
//        int height = resolveSize(getResources().getDisplayMetrics().heightPixels,heightMeasureSpec);
//        setMeasuredDimension(width,height);
////        viewfinderView.setViewHeight(height);
//    }
//
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        viewfinderView.layout(0, 0, right, bottom);
        surfaceView.layout(0, 0, right, bottom);
    }
//
//
//    public ViewfinderView getViewfinderView() {
//        return viewfinderView;
//    }
//
//    public SurfaceView getSurfaceView() {
//        return surfaceView;
//    }
}
